<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>回合制战斗游戏</title>
    <style>
        .hidden {
            display: none;
        }

        button {
            margin: 5px;
            padding: 10px;
            font-size: 16px;
        }
    </style>
</head>

<body>
    <div class="batter-in">
        <div class="yangyuanzhang">
            <img src="../img/yangyuanzhang.png" alt="杨院长">
            <div class="actions hidden">
                <button id="attack">攻击</button>
                <button id="equip">穿装备</button>
                <button id="item">使用物品</button>
            </div>
        </div>
        <div class="enemy">
            <div class="zhoubo">
                <img src="../img/zhoubo.png" alt="周波">
                <div class="enemy-actions hidden">
                    <button id="attackZhoubo">被攻击</button>
                </div>
            </div>
            <div class="hajimi">
                <!-- 哈基米图片和信息 -->
                <div class="enemy-actions hidden">
                    <button id="attackHajimi">被攻击</button>
                </div>
            </div>
        </div>
    </div>

    <script>
        let yangyuanzhang = {
            name: '杨院长',
            hp: 1000,
            mp: 500,
            gongjili: 300,
            fangyuli: 50,
            sudu: 30,
            status: 1,
            wuqi1: 0,
            wuqi2: 0,
            wuqi3: 0,
            gongji(name) {
                alert(`${this.name}对${name.name}发动了攻击，造成了${this.gongjili - name.fangyuli}点伤害`)
                name.hp -= this.gongjili - name.fangyuli
                if (name.hp <= 0) {
                    name.status = 0
                    alert(`${name.name}死亡`)
                } else {
                    alert(`${name.name}剩余血量为${name.hp}`)
                }
            },
            chuanzhuangbei(name) {
                if (name.gongjili == 50) {
                    this.wuqi1 = 1;
                    alert(`${this.name}穿上了${name.name}`)
                    alert(`${name.desc}`)
                    this.gongjili += name.gongjili
                    alert(`${this.name}的攻击力提升了`)
                } else
                    if (name.gongjili == 100) {
                        this.wuqi2 = 1;
                        alert(`${this.name}穿上了${name.name}`)
                        alert(`${name.desc}`)
                        this.gongjili += name.gongjili
                        alert(`${this.name}的攻击力提升了`)
                    } else
                        if (name.gongjili == 400 && yangyuanzhang.wuqi1 == 1 && yangyuanzhang.wuqi2 == 1) {
                            this.wuqi3 = 1;
                            this.wuqi1 = 0;
                            this.wuqi2 = 0;
                            alert(`${this.name}穿上了${name.name}`)
                            alert(`${name.desc}`)
                            this.gongjili += 250;
                            alert(`${this.name}的攻击力提升了`)
                        } else {
                            alert('杨院长不知道什么是电学圣剑')
                        }
            },
            shiyongwuping(name) {
                alert(`${this.name}使用了${name.name},回复了${name.hp}点血量`)
                this.hp += name.hp
            },
            taopao(zhandou) {
                alert(`生为杨院长怎么能逃跑呢，滚回去战斗`)
                yangyuanzhanggongji();
            }
        };
        let zhoubo = {
            name: '周波',
            hp: 500,
            mp: 100,
            gongjili: 0,
            fangyuli: 0,
            sudu: 25,
            status: 1,
            gongji(num, name) {
                if (num == 1) {
                    alert(`${this.name}对${name.name}使用了普通攻击，造成${this.gongjili}点伤害`)
                } else {
                    if (this.mp >= 100) {
                        alert(`${this.name}对${name.name}使用了喵喵叫,消耗100点mp,造成200点伤害`)
                        name.hp -= 200;
                        this.mp -= 100;
                        if (name.hp <= 0) {
                            name.status = 0
                            alert(`${name.name}死亡`)
                        } else {
                            alert(`${name.name}剩余血量为${name.hp}`)
                        }
                    } else {
                        alert(`${this.name}的mp不足，释放失败`)
                        this.gongji(1, name)
                    }

                }
            }
        }
        let hajimi = {
            name: '哈基米',
            hp: 700,
            mp: 30,
            gongjili: 100,
            fangyuli: 100,
            sudu: 50,
            status: 1,
            gongji(num, name) {
                if (num == 1) {
                    alert(`${this.name}对${name.name}使用了普通攻击，造成${this.gongjili - name.fangyuli}点伤害`)
                    name.hp -= this.gongjili - name.fangyuli
                    if (name.hp <= 0) {
                        name.status = 0
                        alert(`${name.name}死亡`)
                    } else {
                        alert(`${name.name}剩余血量为${name.hp}`)
                    }
                } else {
                    if (this.mp >= 10) {
                        alert(`${this.name}对${name.name}使用了撕咬,消耗10点mp,造成100点伤害`)
                        name.hp -= 100;
                        this.mp -= 10;
                        if (name.hp <= 0) {
                            name.status = 0
                            alert(`${name.name}死亡`)
                        } else {
                            alert(`${name.name}剩余血量为${name.hp}`)
                        }
                    } else {
                        alert(`${this.name}的mp不足，释放失败`)
                        this.gongji(1, name)
                    }
                }
            }
        }
        let wuqi = {
            wuqi1: {
                name: '电棒',
                desc: '杨院长用电蚊拍改造的电棒，对哈基米的伤害不够，只能用来电电蚊子',
                gongjili: 50,
            },
            wuqi2: {
                name: '戒尺',
                desc: '杨院长在跳蚤市场淘来的戒尺，金属制品,对哈基米有恐吓效果',
                gongjili: 100,
                texiao() {
                    alert(`对哈基米和周波造成了恐惧效果,速度减少10点`)
                    hajimi.sudu -= 10
                    zhoubo.sudu -= 10
                }
            },
            wuqi3: {
                shiyongzhe: null,
                name: '电学圣剑',
                desc: '杨院长用电棒和戒尺组合而成的电学圣剑,无敌',
                gongjili: 400,
                texiao(name1, name2) {
                    if (name1 == name2) {
                        alert(`对${name1.name}攻击2次，造成${(yangyuanzhang.gongjili - name1.fangyuli) * 2 - 50}点伤害`)
                        name1.hp -= (yangyuanzhang.gongjili - name1.fangyuli) * 2 - 50
                        if (name1.hp <= 0) {
                            name1.status = 0
                            alert(`${name1.name}死亡`)
                        } else {
                            alert(`${name1.name}剩余血量为${name1.hp}`)
                        }
                    }
                    else {
                        alert(`对${name1.name}和${name2.name}发动攻击，分别造成${yangyuanzhang.gongjili - name1.fangyuli}点伤害和${yangyuanzhang.gongjili - name2.fangyuli}点伤害`)
                        name1.hp -= yangyuanzhang.gongjili - name1.fangyuli
                        name2.hp -= yangyuanzhang.gongjili - name2.fangyuli
                        if (name1.hp <= 0) {
                            name1.status = 0
                            alert(`${name1.name}死亡`)
                        } else {
                            alert(`${name1.name}剩余血量为${name1.hp}`)
                        }
                        if (name2.hp <= 0) {
                            name2.status = 0
                            alert(`${name2.name}死亡`)
                        } else {
                            alert(`${name2.name}剩余血量为${name2.hp}`)
                        }
                    }
                }
            }
        }
        let wuping = {
            xuebao: {
                name: '芝士雪豹',
                hp: 500
            },
            ruike: {
                name: '锐克5代',
                hp: 1000
            }
        }
        let isYangYuanZhangTurn = true;

        function updateButtonVisibility() {
            const yangyuanzhangActions = document.querySelector('.yangyuanzhang .actions');
            const enemyActions = document.querySelectorAll('.enemy .enemy-actions');
            yangyuanzhangActions.classList.toggle('hidden', !isYangYuanZhangTurn);
            enemyActions.forEach(actions => {
                actions.classList.toggle('hidden', isYangYuanZhangTurn);
            });
        }

        // 攻击函数
        function attack(attacker, defender) {
            if (defender.hp <= 0) {
                alert(`${defender.name} 已经死亡，无法被攻击。`);
                return;
            }
            let damage = Math.max(attacker.gongjili - defender.fangyuli, 0);
            defender.hp -= damage;
            alert(`${attacker.name} 对 ${defender.name} 造成了 ${damage} 点伤害，剩余血量：${defender.hp}`);
            if (defender.hp <= 0) {
                defender.status = 0;
                alert(`${defender.name} 死亡。`);
                checkGameOver();
            }
        }

        function checkGameOver() {
            if (yangyuanzhang.status === 0) {
                alert('杨院长死亡，游戏结束。');
                document.querySelectorAll('button').forEach(button => button.disabled = true);
            }
        }
        function selectWeapon() {
            let choice = prompt('请选择要装备的武器：' + weapons.map(w => w.name).join(', '));
            let selectedWeapon = weapons.find(w => w.name === choice);
            if (selectedWeapon) {
                yangyuanzhang.chuanzhuangbei(selectedWeapon); // 假设这是穿装备的方法
            } else {
                alert('无效的武器选择');
            }
            endTurn();
        }

        function useItem() {
            let choice = prompt('请选择要使用的物品：' + items.map(i => i.name).join(', '));
            let selectedItem = items.find(i => i.name === choice);
            if (selectedItem) {
                // 假设这是使用物品的方法，并具有恢复效果
                yangyuanzhang.shiyongwuping(selectedItem);
            } else {
                alert('无效的物品选择');
            }
            endTurn();
        }



        // 结束回合
        function endTurn() {
            isYangYuanZhangTurn = !isYangYuanZhangTurn;
            updateButtonVisibility();
            if (!isYangYuanZhangTurn) {
                performEnemyActions();
            }
        }

        function performEnemyActions() {
            // 这里可以添加AI逻辑，决定敌人如何行动
            if (zhoubo.status === 1) {
                // 示例：周波随机攻击杨院长或哈基米
                attack(zhoubo, yangyuanzhang);
            }
            if (hajimi.status === 1) {
                // 示例：哈基米随机攻击杨院长或周波
                attack(hajimi, yangyuanzhang);
            }
        }

        // 绑定按钮事件
        document.getElementById('attack').addEventListener('click', function () {
            // 示例：杨院长攻击周波
            attack(yangyuanzhang, zhoubo);
            endTurn();
        });
        document.getElementById('equip').addEventListener('click', function () {
            // 穿装备逻辑
            endTurn();
        });
        document.getElementById('item').addEventListener('click', function () {
            // 使用物品逻辑
            endTurn();
        });
        document.getElementById('attackZhoubo').addEventListener('click', function () {
            // 周波被攻击逻辑
            attack(yangyuanzhang, zhoubo);
            endTurn();
        });
        document.getElementById('attackHajimi').addEventListener('click', function () {
            // 哈基米被攻击逻辑
            attack(yangyuanzhang, hajimi);
            endTurn();
        });
        // 初始化按钮可见性
        updateButtonVisibility();
    </script>
</body>

</html>